package org.footballmanager.pandafootball.system.controller;

import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.domain.FootChip;
import org.footballmanager.pandafootball.system.form.impl.FootChipSearchForm;
import org.footballmanager.pandafootball.system.service.FootChipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@SessionAttributes("footChipSearchForm")
@RequestMapping("/foot/footChip")
public class FootChipController extends AddAndEditController<FootChip>{
	/* 实体名称 */
	private static final String ENTITYNAME = "footChip";
	private static final String EDITPAGE = String.format(Constants.EDITPAGE, Constants.FOOT, ENTITYNAME);
	private static final String LISTPAGE = String.format(Constants.LISTPAGE, Constants.FOOT, ENTITYNAME);
	private static final String VIEWPAGE = String.format(Constants.VIEWPAGE, Constants.FOOT, ENTITYNAME);

	@Autowired
	private FootChipService footChipService;

    /**
     * 抽象方法
     *
     * @return 实体名称
     */
    @Override
    protected String getEntityName() {
        return ENTITYNAME;
    }

    /**
	 * 初始化
	 * @param map 参数
	 * @param footChipSearchForm 条件参数
	 */
	@ModelAttribute
	public void init(Model map, @ModelAttribute FootChipSearchForm footChipSearchForm){
		FootChipSearchForm newFootBfinfoSearchForm = new FootChipSearchForm();
		if(footChipSearchForm != null){
			newFootBfinfoSearchForm = footChipSearchForm;
		}
		map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), newFootBfinfoSearchForm);
	}

	/**
	 * 获取碎片列表
	 * @param map 参数
	 * @param footChipSearchForm 条件参数
	 * @return 页面
	 */
	@RequestMapping(value="/search")
	public String search(Model map, @ModelAttribute FootChipSearchForm footChipSearchForm){
        footChipService.search(ENTITYNAME, map, footChipSearchForm);
		return LISTPAGE;
	}

    /**
     * 打开编辑页面
     * @param map 参数
     * @param id 主键
     * @return 页面
     */
	@RequestMapping(value = "/edit", method = RequestMethod.GET)
	public String openEditPage(Model map, @RequestParam Long id) {
		map.addAttribute(ENTITYNAME, footChipService.get(id));
		return EDITPAGE;
	}

    /**
     * 打开浏览页面
     * @param map 参数
     * @param id 主键
     * @param footChipSearchForm 条件
     * @return 页面
     */
	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public String openViewPage(Model map, @RequestParam Long id, @ModelAttribute FootChipSearchForm footChipSearchForm) {
		map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), footChipSearchForm);
		map.addAttribute(ENTITYNAME, footChipService.get(id));
		return VIEWPAGE;
	}	

}
